<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <script src="./public/Common/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	</head>
	<body>
		<form action="" method="post">
			
			<table class="table table-hover">
				<tr class="active">
				  <th width="100">glid</th>
				  <?php foreach ($GoodsListAttrData as $v){?>
				  <th><?php echo $v['taname']?></th>
				  <input type="hidden" name="sc_goods_gid" id="" value="<?php echo $v['sc_goods_gid']?>" />
				  <?php }?>
				  <th>库存</th>
				  <th>货号</th>
				  <th>操作</th>
				</tr>
				<?php foreach ($GoodsListData as $v){?>
				<tr>
					<td><?php echo $v['glid']?></td>
					<?php foreach ($v['combine'] as $vv){?>
					<td><?php echo $vv['gtvalue']?></td>
					<?php }?>
					<td><?php echo $v['number']?></td>
					<td><?php echo $v['inventory']?></td>
					<td>
						<a href="" class="btn btn-sm btn-warning">编辑</a>
						<a href="javascript:if(confirm('确定删除吗？')) location.href='';" class="btn btn-sm btn-danger">删除</a>
					</td>
				</tr>
				<?php }?>
				
				<tr class="active">
				  <th width="100" style="line-height: 40px; font-size: 14px;">添加货品</th>
				  <?php foreach ($GoodsListAttrData as $v){?>
				  <th>
				  	<select name="combine[]" class="form-control">
				  		<option value="0">请选择</option>
						<?php foreach ($v['value'] as $vv){?>
						<option value="<?php echo $vv['gtid']?>"><?php echo $vv['gtvalue']?></option>
						<?php }?>
					</select>
	
				  </th>
				  <?php }?>
				  <th>
				  	<input class="form-control" type="text" name="number" id="" value="" />
				  </th>
				  <th>
				  	<input class="form-control" type="text" name="inventory" id="" value="" />
				  </th>
				  <th>
				  	<button class="btn btn-primary" type="submit"> 确定 </button>	
				  </th>
				</tr>
				
			</table>
		</form>
		<script type="text/javascript">
			$(function(){
				var sel =$('select[name="combine[]"]');
				var len =sel.length;
				sel.change(function(){
					var remote={
						'gid':<?php echo Q('get.gid')?>,
						'combine':{}	
					};
					
					for(var i=0;i<len;++i){
						if(sel.eq(i).val()==0)
						{
							return;
						}
						else
						{
							remote.combine[i]=sel.eq(i).val();
						}
					}
					
					$.ajax({
						url:'<?php echo U("check")?>',
						type:'get',
						data:remote,
						dataType:'json',
						success:function(data)
						{
							if(data==0){
								alert('货品已经存在，请修改库存！');
								
								for(var i=0;i<len;++i){
								sel.eq(i).val(0);
							}
							}
						}
					})
				});
			});

		</script>
		
		
	</body>
</html>
